package com.app.freshmenapp.service.impl;

import com.app.freshmenapp.dao.PromptsDao;
import com.app.freshmenapp.entity.Prompts;
import com.app.freshmenapp.service.PromptsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @Auther: Administrator
 * @Date: 2019.07.20 17:07
 * @Description: 学校温馨提示服务层
 */

@Service
@SuppressWarnings("all")
public class PromptsServiceImpl implements PromptsService {

    @Autowired
    private PromptsDao promptsDao;

    @Override
    public boolean addPrompts(Prompts prompts) {
        Prompts prompts1 = promptsDao.saveAndFlush(prompts);
        if(prompts1!=null){
            return true;
        }
        return false;
    }

    @Override
    public boolean deletePrompts(Integer id) {
        if(promptsDao.existsById(id)){
            promptsDao.deleteById(id);
            return true;
        }
        return false;
    }

    @Override
    public boolean updatePrompts(Prompts prompts) {
        Prompts prompts1 = promptsDao.saveAndFlush(prompts);
        if(prompts1!=null){
            return true;
        }
        return false;
    }

    @Override
    public Prompts findById(Integer id) {
        if (promptsDao.existsById(id)){
            Optional<Prompts> optionalPrompts=promptsDao.findById(id);
            return optionalPrompts.get();
        }
        return null;
    }

    @Override
    public List<Prompts> findAllPrompts() {
        return promptsDao.findAll();
    }
}
